
import javax.swing.JTabbedPane;
import javax.swing.SwingWorker;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jy
 */
//双向匹配
public class DoubleMM extends SwingWorker<String, Object>
{
    private StringBuilder m_result = new StringBuilder();
    private String m_str;
    private javax.swing.JTextArea m_jta;
    private int m_maxLength = 3;
    private long m_usedTime;
    public static void main(String[] args)
    {
        
    }
    public DoubleMM(String str, int maxLength, javax.swing.JTextArea jta)
    {
        m_str = str;
        m_maxLength = maxLength;
        m_jta = jta;
    }
    
    public DoubleMM(){}
    
    private String doubleMM()
    {
        long startTime = System.currentTimeMillis();
        MaxMatching mm = new MaxMatching(m_maxLength);
        ReverseMaxMatching rmm = new ReverseMaxMatching(m_maxLength);
        mm.maxMatching(m_str);
        rmm.reverseMaxMatching(m_str);
        
        if(mm.getResult().compareTo(rmm.getResult()) == 0)
        {
            m_result.append(mm.getResult());
        }
        else
        {
            m_result.append("存在歧义");
        }
        long endTime = System.currentTimeMillis();
        m_usedTime = endTime - startTime;
        return getResult();
    }
    
    private String getResult()
    {
        return m_result.toString();
    }
    
    @Override
    protected String doInBackground()
    {
        return doubleMM();
    }
    
    @Override
    protected void done()
    {
        try{
            m_jta.setText(get());
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    public long getUsedTime()
    {
        return m_usedTime;
    }
}
